package com.als.healthymananger.controller.impl;

import com.als.healthymananger.controller.SportsApi;
import com.als.healthymananger.entity.Sport;
import com.als.healthymananger.service.SportsService;
import com.als.healthymananger.utils.RespBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
@RequestMapping("/lib/sport")
public class SportsController implements SportsApi {
    @Autowired
    private SportsService sportsService;

    @Override
    public RespBean createSports(Sport sport) {
        return sportsService.save(sport)? RespBean.ok("添加成功"): RespBean.badRequest("添加失败");
    }

    @Override
    public RespBean deleteSports(int sportId) {
        return sportsService.removeById(sportId)? RespBean.ok("删除成功"): RespBean.badRequest("删除失败");
    }

    @Override
    public RespBean updateSports(int sportId, Sport sport) {
        return sportsService.updateById(sport)? RespBean.ok("修改成功"): RespBean.badRequest("修改失败");
    }

    @Override
    public RespBean getSports(int sportId) {
        Sport sport = null;
        return (sport = sportsService.getById(sportId)) != null? RespBean.ok("获取成功", sport): RespBean.badRequest("获取失败");
    }
}
